<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title><!--{$lang.page.index.title}--></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/lay/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/lay/layui/index.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body" style="padding: 15px;">
        <form name="addItem" method="post" lay-filter="component-form-group" class="layui-form">
          <input type="hidden" value="<!--{$datainfo.id}-->" name="id">
          <input type="hidden" value="<!--{$datainfo.procode}-->" name="procode">
          <input type="hidden" value="<!--{$datainfo.cid}-->" name="cid">
          
          <div class="layui-form-item">
            <div class="layui-inline">
                  <label class="layui-form-label"><!--{$lang.page.public.select}--> <!--{$lang.page.table.product}--></label>
                  <div class="layui-input-block">
                      <select name="proid" lay-verify="proid" lay-filter="brickType">
                         <option value="0"><!--{$lang.page.public.select}--></option>
                         <!--{foreach from=$pro item=item}-->
                         <option data-proname="<!--{$item.title}-->" data-procode="<!--{$item.procode}-->" data-cid="<!--{$item.cid}-->" data-cname="<!--{$item.cname}-->"  value="<!--{$item.id}-->" <!--{if $datainfo.proid eq $item.id}-->selected<!--{/if}-->><!--{$item.title}--></option>
                         <!--{/foreach}-->
                      </select>
                  </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label"><!--{$lang.page.table.name}--></label>
              <div class="layui-input-block">
                <input type="text" name="title" class="layui-input" lay-verify="title" value="<!--{$datainfo.title}-->" readonly>
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label"><!--{$lang.page.table.class}--></label>
              <div class="layui-input-block">
                <input type="text" name="cname" class="layui-input" lay-verify="cname" value="<!--{$datainfo.cname}-->" readonly>
              </div>
            </div>
            
          </div>

          <div class="layui-form-item">
              <label class="layui-form-label"><!--{$lang.page.public.emotional}--></label>
              <div class="layui-inline" id="submue"  style="width:80%;">
                 <table class="layui-table" lay-filter="table">
                <thead>
                    <tr>
                        <td width="25%"><!--{$lang.page.public.bull}--></td>
                        <td width="25%"><!--{$lang.page.public.bear}--></td>
                        <td width="50%"><!--{$lang.page.public.rubric}--></td>
                    </tr>
                </thead>
                <tbody>
                     <tr>
                     <td><input type="text" name="sentiment[bull]" value="<!--{$datainfo.sentiment.bull}-->" lay-verify="bull" placeholder="10%" autocomplete="off" class="layui-input" /></td>
                     <td><input type="text" name="sentiment[bear]" value="<!--{$datainfo.sentiment.bear}-->" lay-verify="bear" placeholder="50%" autocomplete="off" class="layui-input" /></td>
                     <td><!--{$lang.page.public.eminfo}--></td>
                     </tr>
                  </tbody>
                </table>
              </div>
          </div>

          <div class="layui-form-item">
              <label class="layui-form-label"><!--{$lang.page.public.condetail}--></label>
              <div class="layui-inline" id="submue"  style="width:80%;">
                 <table class="layui-table" lay-filter="table">
                <thead>
                    <tr>
                        <td><!--{$lang.page.public.lmin}--></td>
                        <td><!--{$lang.page.public.spre}--></td>
                        <td><!--{$lang.page.public.consize}--></td>
                        <td><!--{$lang.page.public.conmax}--></td>
                        <td><!--{$lang.page.public.conmin}--></td>
                    </tr>
                </thead>
                <tbody>
                     <tr>
                     <td><input type="text" name="contract[lmin]" value="<!--{$datainfo.contract.lmin}-->" lay-verify="requre" placeholder="10" autocomplete="off" class="layui-input" /></td>
                     <td><input type="text" name="contract[spre]" value="<!--{$datainfo.contract.spre}-->" lay-verify="requre" placeholder="40" autocomplete="off" class="layui-input" /></td>
                     <td><input type="text" name="contract[size]" value="<!--{$datainfo.contract.size}-->" lay-verify="requre" placeholder="10" autocomplete="off" class="layui-input" /></td>
                     <td><input type="text" name="contract[max]" value="<!--{$datainfo.contract.max}-->" lay-verify="requre" placeholder="10" autocomplete="off" class="layui-input" /></td>
                     <td><input type="text" name="contract[min]" value="<!--{$datainfo.contract.min}-->" lay-verify="bull" placeholder="10" autocomplete="off" class="layui-input" /></td>
                     </tr>
                  </tbody>
                </table>
              </div>
          </div>

          <div class="layui-form-item">
             <label class="layui-form-label"><!--{$lang.page.public.forecast}--></label>
              <div class="layui-inline" id="submue"  style="width:80%;">

                <table class="layui-table" id="sharetable" lay-filter="table">
                <thead>
                    <tr>
                        <td><!--{$lang.page.table.time}--></td>
                        <td><!--{$lang.page.public.mean}--></td>
                        <td><!--{$lang.page.public.goup}--></td>
                        <td><!--{$lang.page.public.drop}--></td>
                        <td><!--{$lang.page.public.plate}--></td>
                        <td><!--{$lang.page.public.trend}--></td>
                        <td><a class="layui-btn layui-btn-xs addshares"><!--{$lang.page.public.add}--></a></td>
                    </tr>
                </thead>
                  <tbody>
                  <!--{foreach from=$datainfo.forecast item=item key=k}-->
                     <tr>
                     <td><input type="text" name="forecast[<!--{$k}-->][dayn]" value="<!--{$item.dayn}-->" lay-verify="requre" placeholder="1" class="layui-input" /></td>
                     <td><input type="text" name="forecast[<!--{$k}-->][mean]" value="<!--{$item.mean}-->" lay-verify="requre" placeholder="1" class="layui-input" /></td>
                     <td><input type="text" name="forecast[<!--{$k}-->][goup]" value="<!--{$item.goup}-->" lay-verify="requre" placeholder="35" class="layui-input" /></td>
                     <td><input type="text" name="forecast[<!--{$k}-->][drop]" value="<!--{$item.drop}-->" lay-verify="requre" placeholder="40" class="layui-input" /></td>
                     <td><input type="text" name="forecast[<!--{$k}-->][plate]" value="<!--{$item.plate}-->" lay-verify="requre" placeholder="25" class="layui-input" /></td>
                     <td width="18%"><input type="radio" name="forecast[<!--{$k}-->][trend]" value="1" title="<!--{$lang.page.public.goup}-->" <!--{if $item.trend eq 1}--> checked<!--{/if}-->><input type="radio" name="forecast[<!--{$k}-->][trend]" value="2" title="<!--{$lang.page.public.drop}-->" <!--{if $item.trend eq 2}--> checked<!--{/if}-->></td>
                     <td><a class="layui-btn layui-btn-danger layui-btn-xs delshare"><!--{$lang.page.public.del}--></a></td>
                     </tr>
                  <!--{/foreach}-->
                  </tbody>
                </table>
              </div>

          </div>

          <div class="layui-form-item">
            <label class="layui-form-label"><!--{$lang.page.table.status}--></label>
            <div class="layui-input-block">
              <input type="radio" name="status" value="1" title="<!--{$lang.page.table.normal}-->" <!--{if $datainfo.status eq 1}--> checked<!--{/if}-->>&nbsp;&nbsp;<input type="radio" name="status" value="2" title="<!--{$lang.page.table.close}-->" <!--{if $datainfo.status eq 2}--> checked<!--{/if}-->>
            </div>
            </div>
                  
          <div class="layui-form-item layui-layout-admin">
            <div>
              <div class="layui-footer" style="left: 0;">
                <button class="layui-btn" type="button" id="submit" lay-submit lay-filter="submit"><!--{$lang.page.public.submit}--></button>
                <button type="reset" id="reset" class="layui-btn layui-btn-primary"><!--{$lang.page.public.reset}--></button>
                <button type="button" class="layui-btn layui-btn-primary" onClick="xadmin.close();" ><!--{$lang.page.table.back}--></button>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
<script src="/static/lay/layui/layui.js"></script>
  <script type="text/javascript">
    layui.config({
     base: '/static/lay/' //静态资源所在路径
   }).extend({
     xadmin: 'lib/xadmin' //弹窗
   }).use(['jquery', 'layer','xadmin', 'form', 'element','layedit','laydate'], function(){
    var $ = layui.$ //引用jq
    var layer = layui.layer; //独立版的layer无需执行这一句
    var form = layui.form;
     form.render(null, 'component-form-group');
     /* 自定义验证规则 */
    form.verify({
      title: function(value){
        if(value.length < 1){
          return '<!--{$lang.page.table.name}--> <!--{$lang.page.public.nocontent}-->';
        }
      }
      ,proid: function(value){
        if(value < 1){
          return '<!--{$lang.page.public.select}--> <!--{$lang.page.table.product}-->';
        }
      }
      ,description: function(value) {
          return layedit.sync(description);
        }
    });

    form.on('select(brickType)', function(data) {
          var proname = $(data.elem).find("option:selected").attr("data-proname");
          var procode = $(data.elem).find("option:selected").attr("data-procode");
          var cid = $(data.elem).find("option:selected").attr("data-cid");
          var cname = $(data.elem).find("option:selected").attr("data-cname");
          $('input[name="title"]').val(proname);
          $('input[name="procode"]').val(procode);
          $('input[name="cid"]').val(cid);
          $('input[name="cname"]').val(cname);
    });

    $('body').on('click', '.addshares', function() {
      var i = $("#sharetable tbody tr").length;//获取tbody的行数
      if (i > 2) {
        layer.msg('<!--{$lang.page.public.moreset}--> 3 <!--{$lang.page.public.strip}-->', {
            time : 2000
        });
      } else {
        switch(i){
          case 1:
            dayn="1<!--{$lang.page.public.month}-->";
            break;
          case 2:
            dayn="1<!--{$lang.page.public.quarter}-->";
            break;
          default:
            dayn="";
            break;
        }
        var html = '<tr>'+
            '<td><input type="text" name="forecast['+i+'][dayn]" value="'+dayn+'" lay-verify="requre" placeholder="1" class="layui-input" /></td>'+
            '<td><input type="text" name="forecast['+i+'][mean]" value="" lay-verify="requre" placeholder="1" class="layui-input" /></td>'+
            '<td><input type="text" name="forecast['+i+'][goup]" value="" lay-verify="requre" placeholder="35" class="layui-input" /></td>'+
            '<td><input type="text" name="forecast['+i+'][drop]" value="" lay-verify="requre" placeholder="40" class="layui-input" /></td>'+
            '<td><input type="text" name="forecast['+i+'][plate]" value="" lay-verify="requre" placeholder="25" class="layui-input" /></td>'+
            '<td width="18%"><input type="radio" name="forecast['+i+'][trend]" value="1" title="<!--{$lang.page.public.goup}-->"><input type="radio" name="forecast['+i+'][trend]" value="2" title="<!--{$lang.page.public.drop}-->"></td>'+
            '<td><a class="layui-btn layui-btn-danger layui-btn-xs delshare"><!--{$lang.page.public.del}--></a></td>'+
            '</tr>'
        //添加到表格最后
        $(html).appendTo($('#sharetable tbody:last'));
        form.render();
      }
    });
    $('body').on('click', '.delshare', function() {
      if ($('#sharetable tbody tr').length === 1) {
        layer.msg('<!--{$lang.page.public.onenodel}-->', {
            time : 2000
        });
      } else {
        //删除当前按钮所在的tr
        $(this).closest('tr').remove();
      }
    });
    
    form.on('submit(submit)', function (data) {
          $('#submit').attr("disabled",true);
          $('#submit').addClass('layui-btn-disabled');
              $.post('#',data.field,function(res){
                  if(res.code == 200){
                      layer.msg(res.msg);
                      setTimeout(() => {
                          window.parent.location.reload();
                          xadmin.close();
                      }, 1000);
                  }else{
                      layer.msg(res.msg);
                  }
              })
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    //重置按钮，可以提交失败的时候再次提交
    $('#reset').click(function(){
        $('#submit').removeAttr("disabled");
        $('#submit').removeClass('layui-btn-disabled');
    });

  });

  </script>
</body>
</html>

